<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>转办代理实例</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<div style="height: 100%;">
    <div class="tablesize roles" style=" padding:10px">
        <table id="bpmTaskExeItem" lay-filter="bpmTaskExeItem"></table>
    </div>
</div>
<script type="text/html" id="headerToolsBar">
    <div class="ccpui-enterSel">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="reset">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delSome">
            <i class="layui-icon layui-icon-delete"></i>
            <span>批量取消</span>
        </a>
    </div>

    <form class="layui-form" action="" lay-filter="searchForm" style="margin-top:10px">
        <div class="table-top-filter bpmTaskExeLable">
            <div class="table-filter-alone">
                <label class="layui-form-label">请求标题</label>
                <input type="text" name="Q_subject_SL" id="subject" class="layui-input filter-value"
                       placeholder="请求标题"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">流程名称</label>
                <input type="text" name="Q_processName_SL" id="processName" class="layui-input filter-value"
                       placeholder="流程名称"/>
            </div>
            <div class="table-filter-alone" >
                <label class="layui-form-label">转办（代理）人</label>
                <input type="text" name="Q_assigneeName_SL" id="assignName" class="layui-input filter-value" placeholder="转办（代理）人"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">转办（代理）类型</label>
                <select name="Q_status_S" id="status" class="layui-input filter-value">
                    <option value="">所有</option>
                    <option value="0">初始状态</option>
                    <option value="1">完成任务</option>
                    <option value="2">取消转办（代理）</option>
                </select>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">创建人</label>
                <input type="text" name="Q_creator_SL" id="creator" class="layui-input filter-value"
                       placeholder="创建人" />
            </div>
            <span class="_cjr"></span>
            <div class="table-filter-alone">
                <label class="layui-form-label">创建时间</label>
                <input type="text" name="Q_createTime_DL" id="createTime" class="layui-input filter-value" placeholder="开始时间" autocomplete="off"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">至</label>
                <input type="text" name="Q_endCreateTime_DG" id="endCreateTime" class="layui-input filter-value" placeholder="结束时间" autocomplete="off"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">当前状态</label>
                <select name="Q_assignType_S" id="assignType" class="layui-input filter-value">
                    <option value="">所有</option>
                    <option value="1">代理</option>
                    <option value="2">转办</option>
                </select>

            </div>
        </div>
    </form>
    </div>
</script>
<script type="text/html" id="managerBar">
    {{# if(d.status == 0){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">取消</a>
    {{# } }}
</script>
<script>

    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'util', 'commons', 'setter', 'totalFilter', 'common', 'laydate','admin'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var util = layui.util;
        var $ = layui.$;
        var laydate = layui.laydate;
        var setter = layui.setter;
        var commons = layui.commons;
        var common = layui.common;
        var totalFilter = layui.totalFilter;
        var admin = layui.admin;

        var dataPrivacyLevel;
        var privacyLevel = ${privacyLevel};

        var tableH = commons.tabHeight();
        if(screen.width<=1366){
            $("._cjr").html("<br>")
        }
        table.on('checkbox', function(obj){
            if(obj.type==="all"){
                $("input[type='checkbox']").each(function() {
                    if ($(this).prop('disabled')) {
                        $(this).prop("checked",false);
                        $(this).next().removeClass("layui-form-checked");
                    }
                });
            }
        });

        table.render({
            elem: '#bpmTaskExeItem'
            , cellMinWidth: 80
            ,defaultToolbar: ['filter', 'print']
            , title: '流程实例列表'
            , height: tableH
            , url: serverPath.workflowPath+setter.workflowLinkPath + 'bpmTaskExe/list'
            , toolbar: '#headerToolsBar'
            ,autoSort: false
            , page: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'subject', title: '请求标题', sort: true, align: 'center', event: 'processDetail',minWidth: 400, style: 'color:#1E9FFF;cursor:pointer'}
                , {field: 'processName', title: '流程名称', sort: true, align: 'center'}
                , {field: 'creator', title: '创建人', sort: true, align: 'center', event: 'creator', style: 'color:#1E9FFF;cursor:pointer'}
                , {field: 'assigneeName', title: '转办（代理）人', sort: true, align: 'center', event: 'assigneeName', style: 'color:#1E9FFF;cursor:pointer'}
                , {
                    field: 'createTime', title: '创建时间', sort: true, align: 'center', templet: function (d) {
                        if (d.createTime== undefined) {
                            return "";
                        } else {
                            return util.toDateString(d.createTime, "yyyy-MM-dd");
                        }
                    }
                }
                , {
                    field: 'exeTime', title: '结束时间', sort: true, align: 'center', templet: function (d) {
                        if (d.exeTime== undefined) {
                            return "";
                        } else {
                            return util.toDateString(d.exeTime, "yyyy-MM-dd");
                        }
                    }
                }
                , {
                    field: 'status', title: '转办(代理)类型', sort: true, align: 'center', templet: function (d) {
                        if (d.status == undefined) {
                            return "";
                        }
                        if (d.status == 0) {
                            return '<span style="color: #15cc08;">初始状态</span>';
                        }
                        if (d.status == 1) {
                            return '<span style="color: #15cc08;">完成任务</span>';
                        }
                        if (d.status == 2) {
                            if (d.assignType == 1) {
                                return '<span style="color: #cc0c00;">取消代理</span>';
                            }else {
                                return '<span style="color: #cc0c00;">取消转办</span>';
                            }
                        }
                        if (d.status == 3) {
                            return '<span style="color: #15cc08;">其他</span>';
                        }
                    }
                }
                , {
                    field: 'assignType', title: '当前状态', sort: true, align: 'center', templet: function (d) {
                        if (d.assignType== undefined) {
                            return "";
                        } if (d.assignType == 1) {
                            return '<span style="color: #15cc08;">代理</span>';
                        } if (d.assignType == 2) {
                            return '<span style="color: #15cc08;">转办</span>';
                        }
                        if (d.assignType == 3) {
                            return '<span style="color: #15cc08;">流转</span>';
                        }
                        if (d.assignType == 4) {
                            return '<span style="color: #15cc08;">多级转办</span>';
                        }
                    }
                }
                , { title: '管理', toolbar: '#managerBar', width: 120, align: 'center'}
            ]]
            ,done:function (res) {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel')
                commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
                commons.reflashDate({startName: '#exeTime', endName: '#endExeTime'});
                //status!=0时，无法被选中
                var dataArr = res.data;
                if(dataArr!=null) {
                    for (var i = 0; i < dataArr.length; i++) {
                        if (dataArr[i]["status"] != 0) {
                            $("tr[data-index=" + dataArr[i]['LAY_TABLE_INDEX'] + "] input[type='checkbox']").prop("disabled", true);
                        }
                    }
                }
            }
        });
        totalFilter.init('bpmTaskExeItem');

        //刷新事件
        function reload(){
            table.reload('bpmTaskExeItem', {
                page: {
                    curr: 1
                }
            });
            totalFilter.init('bpmTaskExeItem');
        }

        table.on('toolbar(bpmTaskExeItem)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'query':
                    common.tableConditionRender("bpmTaskExeItem", "searchForm", {where: {}}, false);
                    break;
                case 'reset':
                    common.tableConditionRender("bpmTaskExeItem", "searchForm", {where: {}}, true);
                    break;
                case 'delSome':
                    if (data.length === 0) {
                        layer.msg('请选择记录！',{icon:5});
                    } else {
                        var seleIds = [];
                        for (var i = 0; i < data.length; i++) {
                            if(data[i].status==0) {
                                seleIds.push(data[i].id);
                            }
/*                            if(data[i].status==1){
                                layer.msg('请只选择转办（代理）类型为初始状态的流程',{icon:5});
                                return false;
                            }*/
                        }
                        if (seleIds.length<1) {
                            layer.msg('请选择记录！',{icon:5});
                            return false;
                        }
                        var s = seleIds.join(",");
                        var iframeWin;
                        layer.open({
                            type: 2,
                            title: "批量取消转办",
                            shade: 0.3,
                            area: ['550px', '310px'],
                            btn:['确定','关闭'],
                            content:serverPath.workflowPath + setter.workflowLinkPath + 'bpmTaskExe/view/delBatch?ids=' + s,
                            success: function(layero, index){
                                iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            },
                            yes:function (index,layero) {
                                //执行iframe页的save方法
                                iframeWin.save(index,reload);
                            }
                        });
                    }
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(bpmTaskExeItem)', function (obj) {
            var data = obj.data;
            var runId = data.runId;
            // 获取密级
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath+"processRun/getPrivacyLevelByRunId",
                data:{runId: runId},
                type: "post",
                dataType: 'json',
                success: function (result) {
                    dataPrivacyLevel = result;
                    if (privacyLevel < dataPrivacyLevel) {
                        layer.msg('密级不足,无法执行该操作', {icon: 5});
                    }else {
                        switch (obj.event) {
                            case 'del':
                                var iframeWin;
                                parent.layer.open({
                                    type: 2,
                                    title: "取消转办（代理）",
                                    shade: 0.3,
                                    area: ['550px', '300px'],
                                    btn:['确定','关闭'], content:serverPath.workflowPath + setter.workflowLinkPath + 'bpmTaskExe/view/delBatchOnlyOne?id=' + data.id,
                                    success: function(layero, index){
                                        iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                                    },
                                    yes:function (index,layero) {
                                        //执行iframe页的save方法
                                        iframeWin.dataFormSave(index,reload);
                                    }
                                });
                                break;
                            //请求标题
                            case 'processDetail':
                                var isNeedReload=true;
                                layer.open({
                                    type: 2,
                                    title: "流程明细",
                                    area: ['1000px', '585px'],
                                    content: serverPath.workflowPath + setter.workflowLinkPath + 'processRun/view/info?runId=' + runId,
                                    cancel: function () {
                                        isNeedReload = false;
                                    },
                                    end: function(index){
                                        if (isNeedReload) {
                                            table.reload('bpmTaskExeItem', {
                                                page: {
                                                    curr: 1
                                                }
                                            });
                                            totalFilter.init('bpmTaskExeItem');
                                            return false;
                                        }
                                    }

                                });
                                break;
                            //创建人
                            case 'creator':
                                layer.open({
                                    type: 2,
                                    area: ['1000px', '585px'],
                                    title: ['用户信息'],
                                    content:serverPath.systemPath+setter.sysLinkPath +'sysUser/view/view?userId=' + data.creatorId
                                });
                                break;
                            //转办（代理）人
                            case 'assigneeName':
                                layer.open({
                                    type: 2,
                                    area: ['1000px', '585px'],
                                    title: ['用户信息'],
                                    content:serverPath.systemPath+setter.sysLinkPath +'sysUser/view/view?userId=' + data.assigneeId
                                });
                                break;
                        }
                    }
                }
            });

        });
        commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
        window.Initialization = function () {
            commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
        };
        common.tableSort("bpmTaskExeItem",{show:window.Initialization});
    });
</script>
<style>
    .bpmTaskExeLable .table-filter-alone .layui-form-label{
        width: 142px;
    }
</style>
</body>
</html>